package cn.ylg.com.baisibudeijie.mvp.view.impl;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import cn.ylg.com.baisibudeijie.ChatApplication;
import cn.ylg.com.baisibudeijie.mvp.presenter.impl.MvpBasePresenter;
import cn.ylg.com.baisibudeijie.mvp.view.MvpView;

/**
 * Created by MyPC on 2016/10/18.
 */
public abstract class MvpActivity<P extends MvpBasePresenter> extends AppCompatActivity implements MvpView{
    protected  P presenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((ChatApplication) getApplication()).addActivity(this);
        presenter =bindPresenter();
        //中介要关联view
        if (presenter!=null){
            presenter.attach(this);
        }
    }
    //入门;
    public abstract  P bindPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解除绑定;
        if (presenter!=null){
            presenter.deattach();
        }
        ((ChatApplication) getApplication()).removeActivity(this);
    }
}
